/**
 * 描述：${controller.entityComment}Controller<br/>
 * 修改描述：
 * Copyright (c) 2024-2034, ${author} (${authorMail}).
<#if withGNULicense??>
 * <p>
 * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE 3.0;
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.gnu.org/licenses/lgpl.html
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
</#if>
 */
package ${controller.basePackage}.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.util.MultiValueMap;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
<#if controller.validProperty??>
import org.springframework.web.bind.annotation.PatchMapping;
</#if>
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import ${controller.basePackage}.model.${controller.entityTypeSimpleName};
import ${controller.basePackage}.service.${controller.entityTypeSimpleName}Service;
import com.tx.core.paged.model.PagedList;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

/**
 * ${controller.entityComment}控制层<br/>
 * @author [${author}]
 * @version [${version}]
 * @since [${version}]
 */
@Api(tags = "${controller.entityComment}API")
@RestController
@RequestMapping({"/${controller.entityTypeSimpleName?replace("([a-z])([A-Z]+)","$1_$2","r")?lower_case}","/api/${controller.entityTypeSimpleName?replace("([a-z])([A-Z]+)","$1_$2","r")?lower_case}"})
public class ${controller.entityTypeSimpleName}Controller {
    
    //${controller.entityComment}业务层
    @Resource(name = "${controller.entityTypeSimpleName?uncap_first}Service")
    private ${controller.entityTypeSimpleName}Service ${controller.entityTypeSimpleName?uncap_first}Service;
    
	/**
     * 根据主键查询${controller.entityComment}实例<br/> 
     * <功能详细描述>
     * @param ${controller.pkProperty.propertyName} [主键]
     * @return [${controller.entityTypeSimpleName}]
     */
	@ApiOperation(value = "获取${controller.entityComment}")
	@GetMapping("/{${controller.pkProperty.propertyName}}")
    public ${controller.entityTypeSimpleName} findBy${controller.pkProperty.propertyName?cap_first}(@PathVariable(value = "${controller.pkProperty.propertyName}") ${controller.pkProperty.propertyTypeSimpleName} ${controller.pkProperty.propertyName}) {
        ${controller.entityTypeSimpleName} ${controller.entityTypeSimpleName?uncap_first} = this.${controller.entityTypeSimpleName?uncap_first}Service.findBy${controller.pkProperty.propertyName?cap_first}(${controller.pkProperty.propertyName});
        return ${controller.entityTypeSimpleName?uncap_first};
    }

<#if controller.codeProperty??>
	/**
     * 根据编码查询${controller.entityComment}实例<br/> 
     * <功能详细描述>
     * @param ${controller.codeProperty.propertyName} [编码]
     * @return [${controller.entityTypeSimpleName}]
     */
    @ApiOperation(value = "根据编码获取${controller.entityComment}")
    @GetMapping("/code/{code}")
    public ${controller.entityTypeSimpleName} findBy${controller.codeProperty.propertyName?cap_first}(@PathVariable(value = "${controller.codeProperty.propertyName}") ${controller.codeProperty.propertyTypeSimpleName} ${controller.codeProperty.propertyName}) {
        ${controller.entityTypeSimpleName} ${controller.entityTypeSimpleName?uncap_first} = this.${controller.entityTypeSimpleName?uncap_first}Service.findBy${controller.codeProperty.propertyName?cap_first}(${controller.codeProperty.propertyName});
        return ${controller.entityTypeSimpleName?uncap_first};
    }
    
</#if>
    /**
     * 查询${controller.entityComment}实例列表<br/>
     * <功能详细描述>
<#if controller.validProperty??>
     * @param ${controller.validProperty.propertyName} [是否有效]
</#if>
     * @return [List<${controller.entityTypeSimpleName}>]
     */
    @ApiOperation(value = "获取${controller.entityComment}列表")
    @GetMapping("/list")
    public List<${controller.entityTypeSimpleName}> queryList(
<#if controller.validProperty??>
			@RequestParam(value="${controller.validProperty.propertyName}",required=false) Boolean ${controller.validProperty.propertyName},
</#if>
    		@RequestParam MultiValueMap<String, String> request
    	) {
        Map<String, Object> params = new HashMap<>();
	<#if controller.codeProperty??>
		params.put("code", request.getFirst("code"));
	</#if>
	<#if controller.nameProperty??>
		params.put("name", request.getFirst("name"));
	</#if>
    	
        List<${controller.entityTypeSimpleName}> resList = this.${controller.entityTypeSimpleName?uncap_first}Service.queryList(
<#if controller.validProperty??>
			${controller.validProperty.propertyName},
</#if>
			params         
        );
  
        return resList;
    }
    
    /**
     * 查询${controller.entityComment}实例分页列表<br/>
     * <功能详细描述>
<#if controller.validProperty??>
     * @param ${controller.validProperty.propertyName} [是否有效]
</#if>
     * @param pageSize [每页显示条数]
     * @param pageNumber [第几页]
     * @return [List<${controller.entityTypeSimpleName}>]
     */
    @ApiOperation(value = "获取${controller.entityComment}分页列表")
    @GetMapping("/pages/{pageSize}/{pageNumber}")
    public PagedList<${controller.entityTypeSimpleName}> queryPagedList(
    		@PathVariable(value = "pageSize", required = true) int pageSize,
    		@PathVariable(value = "pageNumber", required = true) int pageNumber,
<#if controller.validProperty??>
			@RequestParam(value="${controller.validProperty.propertyName}",required=false) Boolean ${controller.validProperty.propertyName},
</#if>
            @RequestParam MultiValueMap<String, String> request
    	) {
		Map<String, Object> params = new HashMap<>();
	<#if controller.codeProperty??>
		params.put("code", request.getFirst("code"));
	</#if>
	<#if controller.nameProperty??>
		params.put("name", request.getFirst("name"));
	</#if>

        PagedList<${controller.entityTypeSimpleName}> resPagedList = this.${controller.entityTypeSimpleName?uncap_first}Service.queryPagedList(
<#if controller.validProperty??>
			${controller.validProperty.propertyName},
</#if>
			params,
			pageNumber,
			pageSize
        );
        return resPagedList;
    }
    
    /**
     * 校验是否重复<br/>
     * <功能详细描述>
	 * @param exclude${controller.pkProperty.propertyName?cap_first}
     * @param params
     * @return boolean [返回类型说明]
     * @exception throws [异常类型] [异常说明]
     * @see [类、类#方法、类#成员]
     */
    @ApiOperation(value = "判断${controller.entityComment}是否存在")
    @GetMapping("/exists")
    public boolean exists(
            @RequestParam(value = "exclude${controller.pkProperty.propertyName?cap_first}", required = false) ${controller.pkProperty.propertyTypeSimpleName} exclude${controller.pkProperty.propertyName?cap_first},
            @RequestParam Map<String, String> params) {
        params.remove("exclude${controller.pkProperty.propertyName?cap_first}");
        boolean flag = this.${controller.entityTypeSimpleName?uncap_first}Service.exist(params, exclude${controller.pkProperty.propertyName?cap_first});
        return flag;
    }
    
<#if (controller.parentIdProperty?? || controller.parentProperty??)>
    /**
     * 根据条件查询${controller.entityComment}子级列表<br/>
     * <功能详细描述>
     * @param parentId [返回类型说明]
<#if controller.validProperty??>
     * @param valid
</#if>
     * @param request
     * @return [参数说明]
     * 
     * @return PagedList<T> [返回类型说明]
     * @exception throws [异常类型] [异常说明]
     * @see [类、类#方法、类#成员]
     */
    @ApiOperation(value = "获取${controller.entityComment}子列表")
    @GetMapping("/children/{parentId}")
    public List<${controller.entityTypeSimpleName}> queryChildren(
            @PathVariable(value = "parentId", required = true) ${controller.pkProperty.propertyTypeSimpleName} parentId,
	<#if controller.validProperty??>
			@RequestParam(value="${controller.validProperty.propertyName}",required=false) Boolean ${controller.validProperty.propertyName},
	</#if>
            @RequestParam MultiValueMap<String, String> request) {
        Map<String, Object> params = new HashMap<>();
	<#if controller.codeProperty??>
		params.put("code", request.getFirst("code"));
	</#if>
	<#if controller.nameProperty??>
		params.put("name", request.getFirst("name"));
	</#if>
	
        List<${controller.entityTypeSimpleName}> resList = this.${controller.entityTypeSimpleName?uncap_first}Service
                .queryChildrenByParentId(parentId,<#if controller.validProperty??> valid,</#if> params);
        
        return resList;
    }
    
    /**
     * 根据条件查询${controller.entityComment}子、孙级列表<br/>
     * <功能详细描述>
     * @param parentId
     * @param valid
     * @param request
     * @return [参数说明]
     * 
     * @return PagedList<T> [返回类型说明]
     * @exception throws [异常类型] [异常说明]
     * @see [类、类#方法、类#成员]
     */
    @ApiOperation(value = "获取${controller.entityComment}后代列表")
    @GetMapping("/descendants/{parentId}")
    public List<${controller.entityTypeSimpleName}> queryDescendants(
            @PathVariable(value = "parentId", required = true) ${controller.pkProperty.propertyTypeSimpleName} parentId,
	<#if controller.validProperty??>
			@RequestParam(value="${controller.validProperty.propertyName}",required=false) Boolean ${controller.validProperty.propertyName},
	</#if>
            @RequestParam MultiValueMap<String, String> request) {
        Map<String, Object> params = new HashMap<>();
	<#if controller.codeProperty??>
		params.put("code", request.getFirst("code"));
	</#if>
	<#if controller.nameProperty??>
		params.put("name", request.getFirst("name"));
	</#if>
        
        List<${controller.entityTypeSimpleName}> resList = this.${controller.entityTypeSimpleName?uncap_first}Service
                .queryDescendantsByParentId(parentId,<#if controller.validProperty??> valid,</#if> params);
        
        return resList;
    }
    
</#if>
    /**
     * 新增${controller.entityComment}实例
     * <功能详细描述>
     * @param ${controller.entityTypeSimpleName?uncap_first} [${controller.entityComment}]
     * @return [boolean]
     */
    @ApiOperation(value = "新增${controller.entityComment}")
    @PostMapping(value = "")
    public boolean add(${controller.entityTypeSimpleName} ${controller.entityTypeSimpleName?uncap_first}) {
        this.${controller.entityTypeSimpleName?uncap_first}Service.insert(${controller.entityTypeSimpleName?uncap_first});
        return true;
    }
    
    /**
     * 更新${controller.entityComment}实例<br/>
     * <功能详细描述>
     * @param ${controller.entityTypeSimpleName?uncap_first} [${controller.entityComment}]
     * @return [boolean]
     */
    @ApiOperation(value = "更新${controller.entityComment}")
    @PutMapping("/{${controller.pkProperty.propertyName}}")
    public boolean update(@PathVariable(value = "${controller.pkProperty.propertyName}") ${controller.pkProperty.propertyTypeSimpleName} ${controller.pkProperty.propertyName},${controller.entityTypeSimpleName} ${controller.entityTypeSimpleName?uncap_first}) {
        boolean flag = this.${controller.entityTypeSimpleName?uncap_first}Service.updateBy${controller.pkProperty.propertyName?cap_first}(${controller.pkProperty.propertyName},${controller.entityTypeSimpleName?uncap_first});
        return flag;
    }
    
    /**
     * 删除${controller.entityComment}实例<br/> 
     * <功能详细描述>
     * @param ${controller.pkProperty.propertyName} [主键]
     * @return [boolean]
     */
	@ApiOperation(value = "删除${controller.entityComment}")
    @DeleteMapping("/{id}")
    public boolean deleteBy${controller.pkProperty.propertyName?cap_first}(@PathVariable(value = "${controller.pkProperty.propertyName}") ${controller.pkProperty.propertyTypeSimpleName} ${controller.pkProperty.propertyName}) {
        boolean flag = this.${controller.entityTypeSimpleName?uncap_first}Service.deleteBy${controller.pkProperty.propertyName?cap_first}(${controller.pkProperty.propertyName});
        return flag;
    }
    
<#if controller.validProperty??>
    /**
     * 禁用${controller.entityComment}实例
     * <功能详细描述>
     * @param ${controller.pkProperty.propertyName} [主键]
     * @return boolean [返回类型说明]
     */
    @ApiOperation(value = "禁用${controller.entityComment}")
    @PatchMapping("/disable/{${controller.pkProperty.propertyName}}")
    public boolean disableBy${controller.pkProperty.propertyName?cap_first}(@PathVariable(value = "${controller.pkProperty.propertyName}") ${controller.pkProperty.propertyTypeSimpleName} ${controller.pkProperty.propertyName}) {
        boolean flag = this.${controller.entityTypeSimpleName?uncap_first}Service.disableBy${controller.pkProperty.propertyName?cap_first}(${controller.pkProperty.propertyName});
        return flag;
    }
    
    /**
     * 启用${controller.entityComment}实例<br/>
     * <功能详细描述>
     * @param ${controller.pkProperty.propertyName} [主键]
     * @return boolean
     */
    @ApiOperation(value = "启用${controller.entityComment}")
    @PatchMapping("/enable/{${controller.pkProperty.propertyName}}")
    public boolean enableBy${controller.pkProperty.propertyName?cap_first}(@PathVariable(value = "${controller.pkProperty.propertyName}") ${controller.pkProperty.propertyTypeSimpleName} ${controller.pkProperty.propertyName}) {
        boolean flag = this.${controller.entityTypeSimpleName?uncap_first}Service.enableBy${controller.pkProperty.propertyName?cap_first}(${controller.pkProperty.propertyName});
        return flag;
    }
    
</#if>
}